import 'package:flutter/material.dart';
import '../config/theme_color.dart';
import '../picture/chose_category_list_model.dart';

class HomeCateGoryTabPage extends StatefulWidget {
  const HomeCateGoryTabPage({super.key});

  @override
  State<HomeCateGoryTabPage> createState() => _HomeCateGoryTabPageState();
}

class _HomeCateGoryTabPageState extends State<HomeCateGoryTabPage> {
  List<String> categoryNameList = [
    '反转',
    '逆袭',
    '都市脑洞',
    '家庭',
    '现代言情',
    '时空之旅',
    '总裁',
    '剧情',
    '都市日常',
    '先婚后爱'
  ];
  List<ChoseCategoryListModel> categoryList = [];

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      scrollDirection: Axis.horizontal,
      child: Container(
        color: Colors.white,
        child: Wrap(
          spacing: 10,
          children: getWrapList(),
        ),
      ),
    );
  }

  List<Widget> getWrapList() {
    return List.generate(categoryList.length, (index) {
      ChoseCategoryListModel allModel = categoryList[index];
      return GestureDetector(
        onTap: () {
          setState(() {
            allModel.isChose = !allModel.isChose;
          });
        },
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
          decoration: BoxDecoration(
              color: allModel.isChose
                  ? ThemeColor.orangeFF6924Color
                  : ThemeColor.mainBgColor,
              borderRadius: BorderRadius.circular(4)),
          child: Text(allModel.name),
        ),
      );
    });
  }

  @override
  void initState() {
    super.initState();
    categoryList = ChoseCategoryListModel.getAllList(categoryNameList);
  }
}
